﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LimitManager.aspx.cs" Inherits="LotteryVote.LimitManager" %>

<%@ Import Namespace="LotteryVote.Entity" %>
<%@ Import Namespace="LotteryVote.Utility" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="JS/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="JS/comm.js" type="text/javascript"></script>
    <style type="text/css">
        h3
        {
            color: #fff;
            background: #4C4C4C;
            margin: 0px;
            padding: 10px;
        }
        table
        {
            text-align: center;
            border: solid 1px #fff;
        }
        table thead tr td
        {
            padding: 2px;
            background: #4C4C4C;
            color: #fff;
            height: 40px;
            border-bottom: solid 1px #fff;
            border-right: solid 1px #fff;
        }
        table tbody tr td
        {
            padding: 5px;
            border-bottom: solid 1px #B3B3B3;
        }
        table tbody tr:hover
        {
            background: #ccc;
        }
        table table tbody tr td
        {
            padding: 5px;
            border-bottom: solid 1px #B3B3B3;
            border-right: solid 1px #B3B3B3;
        }
        table input[type='text']
        {
            width: 60px;
            border: solid 1px #B3B3B3;
            height: 20px;
            text-align: center;
        }
        input[type='submit']
        {
            height: 25px;
            margin: 10px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>
            下注限制</h3>
        <table cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <%foreach (var gameType in EnumHelper.GetDescription<GameTypeEnum>())
                      { %>
                    <td colspan="2">
                        <%=gameType.Description%>
                    </td>
                    <%} %>
                    <td rowspan="2">
                        操作
                    </td>
                </tr>
                <tr>
                    <%for (int i = 0; i < EnumHelper.GetDescription<GameTypeEnum>().Count; i++)
                      { %>
                    <td>
                        最小
                    </td>
                    <td>
                        最大
                    </td>
                    <%} %>
                </tr>
            </thead>
            <tr>
                <%foreach (var gameType in EnumHelper.GetDescription<GameTypeEnum>())
                  {
                      var limit = FindBetLimit(gameType.Value); %>
                <td>
                    <input id='least_<%=gameType.Value %>' style="width: 60px" type="text" value='<%=limit.LeastLimit%>'
                        class="betLimit" />
                </td>
                <td>
                    <input id='largest_<%=gameType.Value %>' style="width: 60px" type="text" value='<%=limit.LargestLimit %>' />
                </td>
                <%} %>
                <td>
                    <a href="javascript:updateBetLimit()">Save</a>
                </td>
            </tr>
        </table>
        <h3>
            游戏限制</h3>
        <table cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <td rowspan="2">
                        <%=GetGlobalResourceObject("Resource","CompanyType") %>
                    </td>
                    <td colspan="4">
                        2D
                    </td>
                    <td colspan="4">
                        3D
                    </td>
                    <td colspan="2">
                        4D
                    </td>
                    <td>
                        5D
                    </td>
                    <td rowspan="2">
                        PL2
                    </td>
                    <td rowspan="2">
                        PL3
                    </td>
                    <td rowspan="2">
                        操作
                    </td>
                </tr>
                <tr>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Head") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Last") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Roll") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Roll7") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Head") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Last") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Roll") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Roll7") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Last") %>
                    </td>
                    <td>
                         <%=GetGlobalResourceObject("Resource","Roll") %>
                    </td>
                    <td>
                        <%=GetGlobalResourceObject("Resource","Roll") %>
                    </td>
                </tr>
            </thead>
            <%foreach (var companyTypeDesc in EnumHelper.GetDescription<CompanyType>())
              { %>
            <tr>
                <td>
                    <%=companyTypeDesc.Description%>
                </td>
                <td>
                    <%var gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.TwoDigital, (int)PlayWayEnum.Head).Id;
                      var limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.TwoDigital, (int)PlayWayEnum.Last).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.TwoDigital, (int)PlayWayEnum.Roll).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.TwoDigital, (int)PlayWayEnum.Roll7).Id;
                       var betlimit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId);
                       if (betlimit != null)
                       {
                           limit = betlimit.LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                    <%} %>
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.ThreeDigital, (int)PlayWayEnum.Head).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.ThreeDigital, (int)PlayWayEnum.Last).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.ThreeDigital, (int)PlayWayEnum.Roll).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.ThreeDigital, (int)PlayWayEnum.Roll7).Id;
                       betlimit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId);
                       if (betlimit != null)
                       {
                           limit = betlimit.LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                    <%} %>
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.FourDigital, (int)PlayWayEnum.Last).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.FourDigital, (int)PlayWayEnum.Roll).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.FiveDigital, (int)PlayWayEnum.Roll).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.PL2, 0).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <% gamePlayWayId = FindGamePlayWay((int)GameTypeEnum.PL3, 0).Id;
                       limit = FindGameLimit(companyTypeDesc.Value, gamePlayWayId).LimitValue;
                    %>
                    <input type="text" value='<%=limit %>' id='game_<%=gamePlayWayId %>' class='<%=companyTypeDesc.Description %>' />
                </td>
                <td>
                    <a href="javascript:" id='<%=companyTypeDesc.Value %>' name='<%=companyTypeDesc.Description %>'
                        class="saveGameLimit">Save</a>
                </td>
            </tr>
            <%} %>
        </table>
    </div>
    <div id="Json">
    </div>
    <script type="text/javascript">
        var updateBetLimit = function () {
            $.post("/Web/UpdateBetLimit.ashx", { "Limit": getBetlimitJson() }, function (e) { alert(e); });
        }
        var updateGameBetLimit = function () {
            var saveButton = $(this);
            var companyTypeName = saveButton.attr("name");
            var companyTypeId = saveButton.attr("id");
            var json = getGameBetLimitJson(companyTypeId, companyTypeName);
            //$("#Json").text(json);
            $.post("/Web/UpdateGameBetLimit.ashx", { "Limit": json }, function (e) { alert(e); });
        }
        var getBetlimitJson = function () {
            var betLimitArr = new Array();
            var betLimit = $(".betLimit");
            $(betLimit).each(function (i, obj) {
                obj = $(obj);
                var objId = obj.attr("id");
                var gameId = objId.split("_")[1];
                var largetstId = objId.replace("least", "largest");
                var largestLimit = $("#" + largetstId);
                var itemArr = new Array();
                itemArr.push("{\"GameId\":" + gameId);
                itemArr.push("\"LargestLimit\":" + largestLimit.val());
                itemArr.push("\"LeastLimit\":" + obj.val());
                itemArr.push("\"UserId\":" + getQuery("UserId") + "}");
                betLimitArr.push(itemArr.join());
            });
            var json = "[" + betLimitArr.join() + "]";
            return json;
        }
        var getGameBetLimitJson = function (companyTypeId, companyTypeName) {
            var limitInputs = $("." + companyTypeName);
            var betlimitArr = new Array();
            var userId = getQuery("UserId");
            $(limitInputs).each(function (i, obj) {
                obj = $(obj);
                var gameplayWayId = obj.attr("id").split("_")[1];
                var limitValue = obj.val();
                var itemArr = new Array();
                itemArr.push("{\"CompanyType\":" + companyTypeId);
                itemArr.push("\"GamePlayWayId\":" + gameplayWayId);
                itemArr.push("\"LimitValue\":" + limitValue);
                itemArr.push("\"UserId\":" + userId + "}");
                betlimitArr.push(itemArr.join());
            });
            var json = "[" + betlimitArr.join() + "]";
            return json;
        }
        var printJson = function () { $("#Json").text(json); }
        $(document).ready(function () {
            $(".saveGameLimit").bind("click", updateGameBetLimit);
        });
    </script>
    </form>
</body>
</html>
